#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextEdit>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置标题
    this->setWindowTitle("记事本");
    //创建菜单栏
    QMenuBar* menubar = this->menuBar();
    //设置到窗口中
    this->setMenuBar(menubar);

    //创建菜单与菜单项
    QMenu* menu1 = new QMenu("文件 （&F");
    QAction* action1 = new QAction("打开 (&O)");
    QAction* action2 = new QAction("保存 (&S)");

    //添加菜单和菜单选项到菜单栏
    menu1->addAction(action1);
    menu1->addAction(action2);
    menubar->addMenu(menu1);

    //创建输入框
    QTextEdit* edit = new QTextEdit(this);
    edit->setPlaceholderText("请输入文本内容");

    //绑定槽函数
    connect(action1, &QAction::triggered, this, &MainWindow::openfile);
    connect(action2, &QAction::triggered, this, &MainWindow::savefile);
}

MainWindow::~MainWindow()
{
    delete ui;
}

//打开文件函数
void MainWindow::openfile()
{
    QFileDialog* dialog = new QFileDialog(this);
    QString filename = dialog->getOpenFileName();
}
//保存文件函数
void MainWindow::savefile()
{

}
